package cn.edu.yzu.scholarship.model;

import java.util.List;

import cn.edu.yzu.scholarship.pojo.Pager;

import com.jfinal.ext.plugin.sqlinxml.SqlKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;

public class Group extends Model<Group> {

	private static final long serialVersionUID = 6291316781309088045L;
	
	public static final Group dao = new Group();
	
	public static List<Record> findAllMain() {
		return Db.find(SqlKit.sql("group.findAllMain"));
	}
	
	public static void deleteMainById(String groupId) {
		Db.update(SqlKit.sql("group.deleteMainById"),groupId);
	}
	
	public static void updateMain(String groupId, String groupName) {
		Db.update(SqlKit.sql("group.updateMain"), groupName, groupId);
	}

	public static void createMain(String groupName) {
		Db.update(SqlKit.sql("group.createMain"),groupName);
	}
	
	public static List<Record> findAllByGroupId(String groupId) {
		return Db.find(SqlKit.sql("group.findAllByGroupId"),groupId);
	}
	
	public static void deleteOneStu(String groupId,String xh) {
		Db.update(SqlKit.sql("group.deleteOneStu"),groupId, xh);
	}
	
	public static void insertOneStu(String groupId,String xh) {
		Db.update(SqlKit.sql("group.insertOneStu"),groupId, xh);
	}

	public static void deleteAllByGroupId(String groupId) {
		Db.update(SqlKit.sql("group.deleteAllByGroupId"),groupId);
	}
	
	public static Pager<Record> paginate(String groupId, int pageNumber, int pageSize) {
		return Pager.toPager(Db.paginate(pageNumber, pageSize, 
				"select * ", "from student where xh in (select xh from stuGroupList where groupId = ?)", groupId));
	}

}
